package com.tianzeculture.stagebao.activity.personal;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.activity.artist.InternetCelebrityActivity;
import com.tianzeculture.stagebao.activity.personal.adapter.JobAdapter;
import com.tianzeculture.stagebao.activity.personal.adapter.WorkAdapter;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.bean.AllIndustryBean;
import com.tianzeculture.stagebao.bean.JobBean;
import com.tianzeculture.stagebao.bean.ResultBean;
import com.tianzeculture.stagebao.net.CommonRestUsage;
import com.tianzeculture.stagebao.network.Request;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.util.StatusBarUtil;
import com.tianzeculture.stagebao.util.Util;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/6/19 0019.
 * 选择职业
 */

public class SelectJobActivity extends BaseActivity {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.lvJob)
    ListView lvJob;
    WorkAdapter jobAdapter;

    @Request
    CommonRestUsage commonRestUsage = null;

    private int industryList = 101;//工作列表
    List<AllIndustryBean> allJobList;
    ArrayList<String> strings = new ArrayList<>();
    boolean isEdit;
    boolean isAdd;

    @Override
    public void initUI() {
        super.initUI();
        StatusBarUtil.setWindowStatusBarColor(this, R.color.colorGray_F8);
        tvTitle.setText("选择职业");

        isEdit = getIntent().getBooleanExtra("isEdit", false);
        isAdd = getIntent().getBooleanExtra("isAdd", false);
        lvJob.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                Intent intent = new Intent(SelectJobActivity.this,
                        SelectJobTwoActivity.class);
                intent.putExtra("isEdit", isEdit);
                intent.putExtra("isAdd", isAdd);
                intent.putExtra("Job1", allJobList.get(i));
                startActivityForResult(intent, Util.CHOOSE_JOB);
            }
        });
        commonRestUsage.industryList(industryList);
    }


    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);
        if (taskId == industryList) {
            if (msg.getData()) {
                if (msg.getObj() == null)
                    return;
                allJobList = ((ResultBean) msg.getObj()).getIndustry();
                for (AllIndustryBean bean : allJobList) {
                    strings.add(bean.getTag());
                }
                jobAdapter = new WorkAdapter(this, strings);
                lvJob.setAdapter(jobAdapter);
            }
        }
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_select_job;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Util.CHOOSE_JOB) {
            //取出Intent里的Extras数据
            //取出Bundle中的数据
            String job = data.getStringExtra("JOB");
            Intent intent = getIntent();
            intent.putExtra("JOB", job);
            setResult(Util.CHOOSE_JOB, intent);
            finish();
        }
    }
}
